package com.syq.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.syq.mapper.DtsFootprintMapper;
import com.syq.pojo.DtsCollect;
import com.syq.pojo.DtsFootprint;
import com.syq.service.DtsFootprintService;
import com.syq.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: DtsFootprintServiceImpl
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/7/28 16:46
 */

@Service
public class DtsFootprintServiceImpl implements DtsFootprintService {
    @Autowired
    private DtsFootprintMapper dtsFootprintMapper;

    @Override
    public Object findAll(Integer page, Integer limit, Integer userId, Integer goodsId, String sort, String order) {
        Map<String,Object> map=new HashMap<>();
        Page<DtsFootprint> dtsCollectPage = dtsFootprintMapper.selectPage(new Page<>(page, limit),
                new QueryWrapper<DtsFootprint>()
                        .eq("deleted", false)
                        .eq(!StringUtils.isEmpty(userId), "user_id", userId)
                        .eq(!StringUtils.isEmpty(goodsId), "goods_id", goodsId)
                        .orderBy(!StringUtils.isEmpty(sort), "Asc".equalsIgnoreCase(order), sort));
        map.put("total",dtsCollectPage.getTotal());
        map.put("items",dtsCollectPage.getRecords());
        return ResponseUtil.ok(map);
    }
}
